#include<stdio.h>
#include<malloc.h>
#define QElemType int
#define MAXSIZE 3

typedef struct
{
    QElemType *base;
    int front;
    int rear;
}SqQueue;

int main()
{
    SqQueue L,*p;
    p=&L;
    L.base=(QElemType *)malloc(MAXSIZE*sizeof(QElemType));
    L.front=L.rear=0;

    int EnQueue(SqQueue *Q,int e);
    int DeQueue(SqQueue *Q);
    int GetHead(SqQueue *Q);

    int type,e;
    printf("---------------功能菜单---------------\n");
    printf("【1】入队   【2】出队   【3】取队首元素\n");
    printf("--------------------------------------\n");
    printf("请输入你想要的功能：");
    scanf("%d",&type);
    while(type!=-1)
    {
        switch(type)
        {
            case 1:
            {
                printf("请输入需要入栈的元素：");
                scanf("%d",&e);
                EnQueue(p,e);
                printf("请输入你想要的功能：");
                break;
            }
            case 2:
            {
                e=DeQueue(p);
                if(e!=-1)  printf("元素出栈成功：%d\n",e);
                printf("请输入你想要的功能：");
                break;
            }
            case 3:
            {
                e=GetHead(p);
                printf("栈顶元素的值：%d\n",e);
                printf("请输入你想要的功能：");
                break;
            }
        }
        scanf("%d",&type);
    }
}


int EnQueue(SqQueue *Q,int e)
{
    if((Q->rear+1)%MAXSIZE==Q->front)
    {
        printf("队列已满无法入队\n");
        return 0;
    }
    Q->base[Q->rear]=e;
    Q->rear=(Q->rear+1)%MAXSIZE;
    printf("入队成功%d\n",e);
    return 1;
}

int DeQueue(SqQueue *Q)
{
    int e;
    if(Q->rear==Q->front)
    {
        printf("队列为空无法出队\n");
        return -1;
    }
    e=Q->base[Q->front];
    Q->front=(Q->front+1)%MAXSIZE;
    return(e);
}

int GetHead(SqQueue *Q)
{
    if(Q->front!=Q->rear)  return Q->base[Q->front];
}